import torch.nn as nn
from EfficientNetV2Block import EfficientNetV2Block
from GCABlock import GCABlock


class EfficientNetV2WithGCA(nn.Module):
    def __init__(self, num_classes=5):
        super(EfficientNetV2WithGCA, self).__init__()
        self.stem = nn.Sequential(
            nn.Conv2d(3, 32, kernel_size=3, stride=2, padding=1, bias=False),
            nn.BatchNorm2d(32),
            nn.SiLU(),
        )
        self.block1 = EfficientNetV2Block(32, 64)
        self.gca1 = GCABlock(64)
        self.block2 = EfficientNetV2Block(64, 128)
        self.gca2 = GCABlock(128)
        self.pool = nn.AdaptiveAvgPool2d(1)
        self.fc = nn.Sequential(
            nn.Dropout(0.5),
            nn.Linear(128, num_classes)
        )

    def forward(self, x):
        x = self.stem(x)
        x = self.block1(x)
        x = self.gca1(x)
        x = self.block2(x)
        x = self.gca2(x)
        x = self.pool(x).view(x.size(0), -1)
        x = self.fc(x)
        return x
